package com.arvato.common.interceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * 
 * @author: smallking
 * 
 * @Descibe: 拦截没有权限的请求 
 * 
 * @Date: 2018年6月5日 上午11:32:04
 */
public class ArvatoInterceptor implements HandlerInterceptor {

	private static final Logger logger = LoggerFactory.getLogger(ArvatoInterceptor.class);

	/**
	 * 进入controller层之前拦截请求
	 * @param httpServletRequest
	 * @param httpServletResponse
	 * @param o
	 * @return
	 * @throws Exception
	 */
	@Override
	public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object o) throws Exception {
		// 拦截没有权限的请求
		// TODO
		String requestURI = req.getRequestURI();
		logger.info("<<<<<<<<<<<<<<<<<<<<<<" + requestURI + ">>>>>>>>>>>>>>>>>>>>>>>>>>>>");
		/*logger.info("--------------拦截的url" + requestURI + "-----------------");
		PrintWriter printWriter = resp.getWriter();
		printWriter.write("{code:10001}");*/
		return true;
	}
	
	// 在目标方法执行后执行，但在请求返回前，我们仍然可以对 ModelAndView进行修改
	@Override
	public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o,
			ModelAndView modelAndView) throws Exception {
	}
	
	// 在请求已经返回之后执行
	@Override
	public void afterCompletion(HttpServletRequest req, HttpServletResponse httpServletResponse,
			Object o, Exception e) throws Exception {
	}

}
